﻿using System;
using fastCSharp.code.cSharp;

namespace diantou.web.tutorial
{
    /// <summary>
    /// 用户教程
    /// </summary>
    [fastCSharp.code.cSharp.webView.clientType(Name = "diantou.userTutorial")]
    struct userTutorial
    {
        /// <summary>
        /// 教程
        /// </summary>
        public diantou.dataAccess.tutorial Tutorial;
        /// <summary>
        /// 用户信息
        /// </summary>
        public diantou.dataAccess.user User;
        /// <summary>
        /// 教程标识
        /// </summary>
        [fastCSharp.code.cSharp.webView.outputAjax]
        public int Id
        {
            get { return Tutorial == null ? 0 : Tutorial.Id; }
        }
        /// <summary>
        /// 用户标识
        /// </summary>
        internal int UserId
        {
            get { return User == null ? 0 : User.Id; }
        }
        /// <summary>
        /// 是否已经支付点头盾
        /// </summary>
        public bool IsPoint
        {
            get
            {
                if (User == null || Tutorial == null) return false;
                return diantou.dataAccess.tcpCall.user.isTutorial(User.Id, Tutorial.Id);
            }
        }
        ///// <summary>
        ///// 是否存在编辑权限
        ///// </summary>
        //public bool IsPermission
        //{
        //    get
        //    {
        //        return User != null && Tutorial != null && (User.Permission == diantou.dataModel.user.permission.Admin || Tutorial.UserId == User.Id);
        //    }
        //}
        /// <summary>
        /// 学习通过分页数量
        /// </summary>
        private int? passPageCount;
        /// <summary>
        /// 学习通过分页数量
        /// </summary>
        public int PassPageCount
        {
            get
            {
                if (User == null || Tutorial == null) return 0;
                if (passPageCount == null)
                {
                    passPageCount = diantou.dataAccess.tcpCall.userCourse.getTutorialPageCount(User.Id, Tutorial.Id);
                }
                return (int)passPageCount;
            }
        }
        /// <summary>
        /// 继续学习页面
        /// </summary>
        public webView.hashUrl CoursePagePath
        {
            get
            {
                if (Tutorial == null) return default(webView.hashUrl);
                if (User == null) return Tutorial.Path.Index;
                int courseId = diantou.dataAccess.tcpCall.userCourse.getCurrent(User.Id, Tutorial.Id);
                if (courseId == 0) return Tutorial.Path.Index;
                return new diantou.dataModel.path.course { Id = courseId }.Index;
            }
        }
        /// <summary>
        /// 是否通过所有课程
        /// </summary>
        public bool IsPass
        {
            get { return Tutorial != null && PassPageCount == Tutorial.CoursePageCount; }
        }
        ///// <summary>
        ///// 参与课程数量
        ///// </summary>
        //public int CourseCount
        //{
        //    get
        //    {
        //        if (User == null || Tutorial == null) return 0;
        //        return diantou.dataAccess.tcpCall.userTutorialSubject.getSubjectCount(User.Id, Tutorial.Id);
        //    }
        //}
    }
}
